<!-- 个人中心 -->
<template>
	<view class="personal-wrap">
    <navTitle :titleRight="''" :title="'在線簡歷'"></navTitle>
		 <view class="user-top">
			<view class="u-t-info">
				<view class="u-t-i-l">
					<img v-if="personal.avatar" :src="`${$imgUrl}${personal.avatar}`" mode="scaleToFill" alt="">
					<img v-else src="/static/images/user/icon_u_avater_default.png" mode="scaleToFill" alt="">
				</view>
				<view class="u-t-i-c">
					<view class="i-name">{{ personal.realname }}</view>
					<view>{{ work_experience.name }}經驗 · {{ personal.age }}歲 · {{ education_level.name }}</view>
				</view>
				<view class="u-t-i-r" @tap="handleJumpBaseInfo()">
					<img src="/static/images/boss/icon_b_arrow_right.png" mode="scaleToFill" alt="">
				</view>
			</view>
      <!-- 联系方式 -->
      <view class="lxfs-box">
        <view class="lxfs-title">
					<view class="lt-l">
						<img src="/static/images/boss/icon_boss_sjh.png" mode="scaleToFill" alt="">
						<view>聯系方式</view>
					</view>
					<view class="lt-r"></view>
        </view>
				<view class="lxfs-content padding-left-24">
					<p>{{ personal.mobile }}</p>
					<p>{{ personal.email }}</p>
				</view>
				<view class="line_ccc"></view>
				<view class="lxfs-title margin-top-20" @tap="handleJumpGRYS()">
					<view class="lt-l">
						<img src="/static/images/boss/icon_boss_tcjl.png" mode="scaleToFill" alt="">
						<view>個人優勢</view>
					</view>
					<view class="lt-r">
						<img src="/static/images/user/icon_u_edit.png" mode="scaleToFill" alt="">
					</view>
        </view>
				<view class="lxfs-content padding-left-24">{{ summary.content }}</view>
				<view class="line_ccc"></view>
				<view class="lxfs-title margin-top-20">
					<view class="lt-l">
						<img src="/static/images/boss/icon_boss_smrz.png" mode="scaleToFill" alt="">
						<view>求職期望</view>
					</view>
					<view class="lt-r"></view>
        </view>
				<view class="lxfs-content padding-left-24">
					<view class="jy-li" @tap="handleJumpQZQW()">
						<view class="jy-title">
							<view class="jy-t-l" style="flex:1.3;">{{ job_intention_obj.expect_job_name }} {{ job_intention_obj.expect_salary_min }}-{{ job_intention_obj.expect_salary_max }}</view>
							<view class="jy-t-r">
								<view></view>
								<img src="/static/images/boss/icon_b_arrow_right.png" mode="scaleToFill" alt="">
							</view>
						</view>
					</view>
				</view>
				<view class="line_ccc"></view>
				<view class="lxfs-title margin-top-20" :class="resumeInfo.works.length==0?'margin-bottom-10':''" @tap="handleJumpGZJL()">
					<view class="lt-l">
						<img src="/static/images/boss/icon_boss_qz.png" mode="scaleToFill" alt="">
						<view>工作經歷</view>
					</view>
					<view class="lt-r">
						<img style="height: 20px;" src="/static/images/boss/icon_b_arrow_add_img.png" mode="scaleToFill" alt="">
					</view>
        </view>
				<view class="lxfs-content padding-left-24" v-if="resumeInfo.works.length>0">
					<view class="jy-li margin-bottom-10" v-for="(item,index) in resumeInfo.works" :key="index" @tap="handleJumpGZJL(item)">
						<view class="jy-title">
							<view class="jy-t-l">{{ item.company_name }}</view>
							<view class="jy-t-r" style="flex:1.5">
								<view>{{ item.start }}-{{ item.end }}</view>
								<img src="/static/images/boss/icon_b_arrow_right.png" mode="scaleToFill" alt="">
							</view>
						</view>
						<view class="xm-title">{{ item.job_title }}</view>
						<view class="xm-content">工作內容：{{ item.detail }}</view>
					</view>
				</view>
				<view class="line_ccc"></view>
				<view class="lxfs-title margin-top-20" @tap="handleJumpXMJL()">
					<view class="lt-l">
						<img src="/static/images/boss/icon_boss_xmjl.png" mode="scaleToFill" alt="">
						<view>項目經歷</view>
					</view>
					<view class="lt-r">
						<img style="height: 20px;" src="/static/images/boss/icon_b_arrow_add_img.png" mode="scaleToFill" alt="">
					</view>
        </view>
				<view class="lxfs-content padding-left-24" v-if="resumeInfo.project.length>0">
					<view class="jy-li margin-bottom-10" v-for="(item,index) in resumeInfo.project" :key="index" @tap="handleJumpXMJL(item)">
						<view class="jy-title">
							<view class="jy-t-l">{{ item.project_name }}</view>
							<view class="jy-t-r" style="flex:1.5">
								<view>{{ item.start }}-{{ item.end }}</view>
								<img src="/static/images/boss/icon_b_arrow_right.png" mode="scaleToFill" alt="">
							</view>
						</view>
						<view class="xm-title">{{ item.project_role }}</view>
						<view class="xm-content">工作內容：{{ item.description }}</view>
					</view>
				</view>
				<view class="line_ccc"></view>
				<view class="lxfs-title margin-top-20" @tap="handleJumpJYJL()">
					<view class="lt-l">
						<img src="/static/images/boss/icon_boss_jyjl.png" mode="scaleToFill" alt="">
						<view>教育經歷</view>
					</view>
					<view class="lt-r">
						<img style="height: 20px;" src="/static/images/boss/icon_b_arrow_add_img.png" mode="scaleToFill" alt="">
					</view>
        </view>
				<view class="lxfs-content padding-left-24">
					<view class="jy-li" v-for="(item,index) in resumeInfo.educations" @tap="handleJumpJYJL(item)">
						<view class="jy-title">
							<view class="jy-t-l">{{ item.school_name||'--' }}</view>
							<view class="jy-t-r" style="flex:1.5">
								<view>{{ item.start||'--' }}至{{ item.end||'--' }}</view>
								<img src="/static/images/boss/icon_b_arrow_right.png" mode="scaleToFill" alt="">
							</view>
						</view>
						<view class="zy-title">{{ item.level.name||'--' }}{{item.major?'·':''}}{{ item.major }}</view>
					</view>
				</view>
				<view class="line_ccc"></view>
				<view class="lxfs-title margin-top-20">
					<view class="lt-l">
						<img src="/static/images/boss/icon_boss_zdy.png" mode="scaleToFill" alt="">
						<view>自定義添加</view>
					</view>
					<view class="lt-r"></view>
        </view>
				<view class="lxfs-content">
					<view class="zdy-item">
						<view class="zdy-title">
							<view>資格證書</view>
							<img @tap="zdyUploadFile()" src="/static/images/boss/icon_b_arrow_add_img.png" mode="scaleToFill" alt="">
						</view>
						<block>
							<view class="zdy-li" v-for="(item,index) in zgzsList" :key="index">
								<view class="zl-l">
									<img src="/static/images/boss/icon_boss_xmtb.png" mode="scaleToFill" alt="">
									<view>{{ `${item.name}.${item.file_ext}` }}</view>
								</view>
								<img src="/static/images/boss/icon_xc_point.png" @tap="deleteFileZDY(item,index)" mode="scaleToFill" alt="">
							</view>
						</block>
					</view>
					<view class="zdy-item">
						<view class="zdy-title">
							<view>圖片作品</view>
							<img @tap="zdyUploadImg()" src="/static/images/boss/icon_b_arrow_add_img.png" mode="scaleToFill" alt="">
						</view>
						<view class="zi-imgs">
							<view class="zi-img" v-for="(item,index) in tpzpList" :key="index">
								<img class="zp" :src="item.file" mode="scaleToFill" alt="">
								<img class="zp-gb" src="/static/images/boss/icon_xc_close.png" @tap="deleteFileZDY(item,index)" mode="scaleToFill" alt="">
							</view>
						</view>
					</view>
				</view>
      </view>
		</view>
	</view>
</template>

<script>
import { userMyResume,userListFileZDY,userUploadFileZDY,userDeleteFileZDY } from '../../../utils/userApi'
import navTitle from '../components/nav-title.vue';
export default {
	components: {
    navTitle
	},
	data() {
		return {
			resumeInfo:{},
			zgzsList:[],
			tpzpList:[],
			personal:{},
			work_experience:{},
			education_level:{},
			summary:{},
			job_intention_obj:{},
		}
	},
	computed: {},
  onShow(){
		this.resumeInfo={}
		this.personal={}
		this.work_experience={}
		this.education_level={}
		this.summary={}
		this.job_intention_obj={}
		this.getUserMyResume()
	},
	methods: {
		handleJumpBaseInfo(){//用戶基本信息
			uni.navigateTo({ url: '/pages/boss/user/info' })
		},
		handleJumpQZQW(){//求職期望
			uni.navigateTo({ url: `/pages/user/resume/positionCard?expect_job_name=${this.job_intention_obj.expect_job_name||''}&expect_salary_min=${this.job_intention_obj.expect_salary_min}&expect_salary_max=${this.job_intention_obj.expect_salary_max}` })
		},
		handleJumpGZJL(item){//工作經歷
			let str=''
			if(item){
				str=JSON.stringify(item)
			}
			uni.navigateTo({ url: '/pages/user/resume/workCard?str='+str })
		},
		async deleteFileZDY(item,index){
			let res=await userDeleteFileZDY({id:item.id})
			if(res.code==1){
				this.getUserListFileZDY(this.resumeInfo.id)
			}else{
				uni.showToast({
          icon:'none',
          title: res.msg||'系統異常'
        })
			}
		},
    zdyUploadFile(){
      let that=this
      uni.chooseFile({
        count:1,
        extension: ['.pdf'],//文件類型
        success:res=>{
					let file_name=res.tempFiles[0].name
          let tempFiles = res.tempFiles
          let tempFilePaths = res.tempFilePaths
          uni.uploadFile({
            url: `${that.$imgUrl}/api/common/upload`,
            filePath: tempFilePaths[0],
            header: {
              token: uni.getStorageSync('token')
            },
            name: "file",
          }).then(res => {
            let data = JSON.parse(res.data)
            if(data.code==1){
							let upload_file_url=data.data.fullurl
							that.addUploadFile(upload_file_url, file_name,1)
            }else{
              uni.showToast({
                icon:'none',
                title: data.msg||'系統異常'
              })
            }
          })
        }
      })
    },
		zdyUploadImg(){
			let that=this
      uni.chooseImage({
        // original 原图， compressed 压缩图，默认二者都有
        sizeType: ["original", "compressed"],
        // camera 使用相机，album 从相册中选图，默认二者都有
        sourceType: ["camera", "album"],
        count:1,
        // success是必须要写的
        success: function (res) {
					let file_name=res.tempFiles[0].name
          const tempFiles = res.tempFiles
          const tempFilePaths = res.tempFilePaths
          uni.uploadFile({
            url: `${that.$imgUrl}/api/common/upload`,
            filePath: tempFilePaths[0],
            header: {
              token: uni.getStorageSync('token')
            },
            name: "file",
          }).then(res => {
            let data = JSON.parse(res.data)
            if(data.code==1){
							let upload_file_url=data.data.fullurl
							that.addUploadFile(upload_file_url, file_name, 2)
            }else{
              uni.showToast({
                icon:'none',
                title: data.msg||'系統異常'
              })
            }
          })
        }
      })
		},
		async addUploadFile(url,name,type){
			let file_name=name.split('.')
			let res=await userUploadFileZDY({
				file:url,
				name:file_name[0],
				type:type==1?'certificate':'composition',
			})
			if(res.code==1){
				uni.showToast({
          icon:'none',
          title: '上传成功'
        })
				this.getUserListFileZDY(this.resumeInfo.id)
			}else{
				uni.showToast({
          icon:'none',
          title: res.msg||'系統異常'
        })
			}
		},
		handleJumpJYJL(item){//教育經歷
			let str=''
			if(item){
				str=JSON.stringify(item)
			}
			uni.navigateTo({ url: '/pages/user/resume/educationalCard?str='+str })
		},
		handleJumpXMJL(item){//项目經歷
			let str=''
			if(item){
				str=JSON.stringify(item)
			}
			uni.navigateTo({ url: '/pages/user/resume/projectCard?str='+str })
		},
		handleJumpGRYS(){//个人优势
			uni.navigateTo({ url: '/pages/user/resume/advantageCard?content='+this.summary.content })
		},
		async getUserListFileZDY(id){
			let that=this
			let res=await userListFileZDY({id:id})
			if(res.code==1){
				that.tpzpList=res.data.composition
				that.zgzsList=res.data.certificate
			}else{
				uni.showToast({
          icon:'none',
          title: res.msg||'系統異常'
        })
			}
		},
		async getUserMyResume(){
			let res=await userMyResume()
			if(res.code==1){
				this.interview_count=res.data.interview_count
				if(res.data.resume.id){
					this.getUserListFileZDY(res.data.resume.id)
					this.resumeInfo=res.data.resume
					this.personal=res.data.resume.personal
					this.work_experience=res.data.resume.personal.work_experience||{}
					this.education_level=res.data.resume.personal.education_level||{}
					this.summary=res.data.resume.summary||{}
					this.job_intention_obj=res.data.resume.job_intention.length>0?res.data.resume.job_intention[0]:{}
				}
			}else{
				uni.showToast({
          icon:'none',
          title: res.msg||'系統異常'
        })
			}
		}
	}
};
</script>
<style lang="scss" scoped>
.personal-wrap{
	width: 100%;
	height: 100vh;
	background: #F4F6FA;
}
.user-top{
	width: calc(100% - 20px);
  margin: 10px auto 10px;
  background: #fff;
}
.u-t-info{
	width: calc(100% - 30px);
	margin: 0 auto 0;
	padding-top: 15px;
  padding: 15px 0 37px;
	display: flex;
	justify-content: center;
	align-items: center;
}
.u-t-i-l{
	width: 58px;
	height: 58px;
	img{
		width: 100%;
		height: 100%;
		border-radius: 50%;
	}
}
.u-t-i-c{
	width: calc(100% - 85px);
	margin: 0 10px;
	font-size: 13px;
	color: #666666;
	line-height: 18px;
	.i-name{
		font-weight: bolder;
		font-size: 18px;
		color: #333333;
		line-height: 25px;
		padding-bottom: 5px;
	}
}
.u-t-i-r{
	width: 7px;
	height: 12px;
	img{
		width: 100%;
		height: 100%;
	}
}
.lxfs-box{
	padding: 0 17px;
}
.line_ccc{
	border: 0.5px solid #E8E8E8;
}
.lxfs-title{
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-weight: 500;
	font-size: 16px;
	color: #333333;
	.lt-l{
		display: flex;
		justify-content: flex-start;
		align-items: center;
		img{
			height: 18px;
			margin-right: 10px;
		}
	}
	.lt-r{
		img{
			height: 16px;
		}
	}
}
.lxfs-content{
	padding: 10px 0 8px;
	line-height: 26px;
}
.padding-left-24{
	padding-left: 24px !important;
}
.margin-top-20{
	margin-top: 20px;
}
.margin-bottom-10{
	margin-bottom: 20px;
}
.zdy-item{
	background: #F4F6FA;
	border-radius: 6px;
	margin: 5px 0 8px 0;
	border: 1px solid #E8E8E8;
	.zdy-title{
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-weight: 500;
		font-size: 15px;
		color: #333333;
		line-height: 21px;
		padding: 10px;
		img{
			width: 20px;
		}
	}
}
.zi-imgs{
	width: calc(100% - 20px);
	margin: 0 auto 6px;
	border-radius: 6px;
	background: #fff;
	font-size: 15px;
	color: #333333;
	line-height: 21px;
	display: flex;
	padding: 10px;
	justify-content: flex-start;
	align-items: center;
	.zi-img{
		width: calc(25% - 1px);
		height: 70px;
		position: relative;
		margin-right: 7px;
		.zp{
			width: 64px;
			height: 70px;
			border-radius: 6px;
		}
		.zp-gb{
			width: 14px;
			height: 14px;
			position: absolute;
			left: 57px;
			top: -7px;
		}
	}
}
.zdy-li{
	width: calc(100% - 40px);
	margin: 0 auto 6px;
	border-radius: 6px;
	background: #fff;
	font-size: 15px;
	color: #333333;
	line-height: 21px;
	display: flex;
	padding: 10px;
	justify-content: space-between;
	align-items: center;
	.zl-l{
		width: calc(100% - 18px);
		display: flex;
		justify-content: flex-start;
		align-items: center;
		img{
			width: 29px;
			height: 29px;
			margin-right: 10px;
		}
	}
	&>img{
		width: 15px;
	}
}
.jy-title{
	display: flex;
	justify-content: space-between;
	align-items: center;
	.jy-t-l{
		flex: 1;
		font-weight: 500;
		font-size: 15px;
		color: #333333;
		line-height: 21px;
	}
	.jy-t-r{
		flex: 1;
		font-weight: 500;
		font-size: 15px;
		color: #333333;
		line-height: 21px;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		font-size: 12px;
		color: #666666;
		img{
			width: 7px;
			display: block;
			margin-left: 10px;
		}
	}
}
.zy-title,.xm-content{
	margin-top: 5px;
	font-size: 13px;
	color: #666666;
	line-height: 18px;
}
.xm-title{
	margin-top: 10px;
	font-size: 13px;
	color: #666666;
	line-height: 18px;
}
.margin-bottom-10{
	margin-bottom: 12px;
}
</style>
